<?php
/**
 * User: hjd-yao
 * Date: 2019/2/22
 * Time: 16:22
 */

namespace App\Http\Controllers\Lottery;


use App\Helpers\SelfResponse;
use App\Http\Controllers\BackendController;
use Illuminate\Http\Request;
use App\Models\Lottery\WinModel;

class WinController extends BackendController
{
    private static $_winModel;

    public function __construct()
    {
        self::$_winModel = WinModel::init();
    }

    /**
     * 中奖记录列表
     */
    public function index()
    {
        $list = self::$_winModel->paginate($this->getPerPageNum());
        return view('backend::lottery.win.list',[
            'page_title'=>'中奖记录',
            'list'=>$list
        ]);
    }

    /**
     * @title 删除
     */
    public function hx($id)
    {
        $info = self::$_winModel->find($id);

        if(!$info){
            return SelfResponse::error('信息不存在！');
        }

        if($info->status!=1){
            return SelfResponse::error('信息已失效！');
        }
        $info->status=2;
        $info->save();
        return SelfResponse::success('操作成功！','b_lottery_win_index');
    }

    public function zf($id)
    {
        $info = self::$_winModel->find($id);

        if(!$info){
            return SelfResponse::error('信息不存在！');
        }

        if($info->status!=1){
            return SelfResponse::error('信息已失效！');
        }
        $info->status=-1;
        $info->save();
        return SelfResponse::success('操作成功！','b_lottery_win_index');
    }


    /**
     * @title 删除
     */
    public function delete($id)
    {
        $info = self::$_winModel->find($id);

        if(!$info){
            return SelfResponse::error('信息不存在！');
        }

        if(!self::$_winModel->where('id',$id)->delete()){
            return SelfResponse::error('删除失败！');
        }

        return SelfResponse::success('删除成功！','b_lottery_win_index');
    }
}